#include<bits/stdc++.h>
using namespace std;

struct node{
    int d,v,a;
};
int ans1 = 0,ans2 = 0;

node a[100000];
int c1[10000][2];//the place of ce



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T,n,m,L,V;
    cin >> T;
    for (int i = 0;i<T;i++){
        cin >> n >> m >> L >> V;
        for (int j = 0;j <n ;j++)
        {
            cin >> a[i].d >> a[i].v >> a[i].a;
        }
        for(int k = 0;k<m;k++){
            cin >> c1[i][0];
        }
        for (int k = 0;k<n;k++){
            int pan = 0;
            if (a[k].a >= 0 ){
                if (a[k].v > V){
                    for (int j = 0;j<m;j++){
                        if (c1[j][0] > a[k].d){
                            c1[j][1] = 1;
                            pan = 1;
                        }
                        }
                   }
                }
                if (pan == 1) ans1 ++;
            }
        for (int j = 0;j<m;j++){
                if(!c1[i][1]) ans2 ++;
            }
        cout << ans1 <<" "<<ans2 <<"\n";
        }

    return 0;
}


